package fun.diaoer.controller;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import fun.diaoer.common.JsonResult;
import fun.diaoer.entity.DISysPermission;
import fun.diaoer.entity.DISysUser;
import fun.diaoer.entity.vo.VDISysUser;
import fun.diaoer.service.AuthService;
import fun.diaoer.service.security.DiaoerUserDetail;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@RestController
@RequestMapping("/auth")
public class AuthentionController extends AbstractController{
	
	@Autowired
	private AuthService authService;
	
	@PostMapping("isLogin")
	public JsonResult<Boolean> isLogin(){
		return new JsonResult<>(authService.isLogin());
	}
	
	@PostMapping("/login")
	public JsonResult<String> login(@RequestBody DiaoerUserDetail diaoerUserDetail,HttpServletRequest request){
		return new JsonResult<>(authService.login(diaoerUserDetail,request));
	}
	
	@PostMapping("getUserId")
	public JsonResult<String> getUserId(){
		return new JsonResult<>(authService.getUserId());
	}
	
	@PostMapping("getPerms")
	public JsonResult<List<DISysPermission>> getPerms(){
		return new JsonResult<>(authService.getPerms());
	}
	
	@PostMapping("getRoles")
	public JsonResult<List<String>> getRoles(){
		return new JsonResult<>(authService.getRoleds());
	}
	
	@PostMapping("searchUsers")
	public JsonResult<List<DISysUser>> searchUsers(){
		return new JsonResult<>(authService.searchUsers());
	}
	
	@PostMapping("register")
	public JsonResult<Boolean> register(@RequestBody VDISysUser vDISysUser){
		return new JsonResult<>(authService.register(vDISysUser));
	}

}
